// pages/mine/otherOrder/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      type:2,
      dataList:[],
      total_page:0,
      now_page:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let title = '加油订单';
    wx.setNavigationBarTitle({
      title: title,
    })
   
  },
  goComment(){

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    this.setData({
      total_page:0,
      dataList:[]
    });
   this.getData()
  },
  deleteOrder(e){
    let id = e.currentTarget.dataset.id;
    let index = e.currentTarget.dataset.index;

    wx.showModal({
      title:"提示",
      content:"是否确认删除？",
      success:res=>{
        if(res.confirm){
          let url = 'api/userr/delOilOrder';
          var data={
            url: url,
            data:{
              order_id: id
            },
            success:(e)=>{
              if(e.data.code == 1){
                wx.showToast({
                  title: '删除成功',
                  icon:'none',
                })
                let dataList = this.data.dataList;
                dataList.splice(index,1);
                this.setData({
                  dataList:dataList
                });
              }else{
                wx.showToast({
                  title: '删除失败',
                  icon:'none',
                })
              }
            
            }
          };
          app.post(data);
        }
       
      }
    })
    
  },
  getData(now_page = 1){
    let url = 'api/userr/oilOrder';
    var data={
      url: url,
      data:{
        user_id: wx.getStorageSync('userId'),
        now_page:now_page
      },
      success:(e)=>{
        let res = e.data.data;
        console.log(res)
        this.setData({
          total_page:res.total_page,
          dataList:this.data.dataList.concat(res.list)
        });
      }
    };
    app.post(data);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      let now_page = this.data.now_page;
      console.log(now_page,this.data.total_page)
      if(now_page < this.data.total_page){
        now_page++;
        this.setData({
          now_page:now_page
        })
        this.getData(now_page)
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})